package com.xintai.system.controller;

import java.util.List;

import com.xintai.utils.StaticString;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xintai.common.annotation.Log;
import com.xintai.common.core.controller.BaseController;
import com.xintai.common.core.domain.AjaxResult;
import com.xintai.common.enums.BusinessType;
import com.xintai.system.domain.setother.ErpOtherSiJi;
import com.xintai.system.service.IErpOtherSiJiService;
import com.xintai.common.utils.poi.ExcelUtil;
import com.xintai.common.core.page.TableDataInfo;

/**
 * 司机管理Controller
 *
 * @author xintai
 * @date 2021-01-18
 */
@RestController
@RequestMapping("/system/othersiji")
public class ErpOtherSiJiController extends BaseController
{
    @Autowired
    private IErpOtherSiJiService erpOtherSiJiService;

    /**
     * 查询司机管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:othersiji:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpOtherSiJi erpOtherSiJi)
    {
        startPage();
        List<ErpOtherSiJi> list = erpOtherSiJiService.selectErpOtherSiJiList(erpOtherSiJi);
        return getDataTable(list);
    }

    /**
     * 导出司机管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:othersiji:export')")
    @Log(title = "司机管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ErpOtherSiJi erpOtherSiJi)
    {
        List<ErpOtherSiJi> list = erpOtherSiJiService.selectErpOtherSiJiList(erpOtherSiJi);
        ExcelUtil<ErpOtherSiJi> util = new ExcelUtil<ErpOtherSiJi>(ErpOtherSiJi.class);
        return util.exportExcel(list, "other");
    }

    /**
     * 获取司机管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:othersiji:query')")
    @GetMapping(value = "/{otherId}")
    public AjaxResult getInfo(@PathVariable("otherId") Integer otherId)
    {
        return AjaxResult.success(erpOtherSiJiService.selectErpOtherSiJiById(otherId));
    }

    /**
     * 新增司机管理
     */
    @PreAuthorize("@ss.hasPermi('system:othersiji:add')")
    @Log(title = "司机管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpOtherSiJi erpOtherSiJi)
    {
        if (erpOtherSiJiService.verifyOtherSiJi(erpOtherSiJi))
            return AjaxResult.error(StaticString.NameRepeat(erpOtherSiJi.getOtherValue1()));
        return toAjax(erpOtherSiJiService.insertErpOtherSiJi(erpOtherSiJi));
    }

    /**
     * 修改司机管理
     */
    @PreAuthorize("@ss.hasPermi('system:othersiji:edit')")
    @Log(title = "司机管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpOtherSiJi erpOtherSiJi)
    {
        if (erpOtherSiJiService.verifyOtherSiJi(erpOtherSiJi))
            return AjaxResult.error(StaticString.NameRepeat(erpOtherSiJi.getOtherValue1()));
        return toAjax(erpOtherSiJiService.updateErpOtherSiJi(erpOtherSiJi));
    }

    /**
     * 删除司机管理
     */
    @PreAuthorize("@ss.hasPermi('system:othersiji:remove')")
    @Log(title = "司机管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{otherIds}")
    public AjaxResult remove(@PathVariable Integer[] otherIds)
    {
        return toAjax(erpOtherSiJiService.deleteErpOtherSiJiByIds(otherIds));
    }
}